package com.xydtech.ecard.dept.service.impl;

import com.xydtech.common.utils.AESEncryptionUtils;
import com.xydtech.common.utils.StringUtils;
import com.xydtech.ecard.dept.domain.EcardApiSysDept;
import com.xydtech.ecard.dept.mapper.EcardApiSysDeptMapper;
import com.xydtech.ecard.dept.service.IEcardApiSysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 部门Service业务层处理
 *
 * @author busiplat
 * @date 2021-09-24
 */
@Service
public class EcardApiSysDeptServiceImpl implements IEcardApiSysDeptService {
    @Autowired
    private EcardApiSysDeptMapper ecardApiSysDeptMapper;

    /**
     * 电子名片-部门管理-获取同级部门列表
     * @param legalManDeptId
     * @return
     */
    @Override
    public List<EcardApiSysDept> getSameLevelDepts(Long legalManDeptId) {
        return ecardApiSysDeptMapper.getSameLevelDepts(legalManDeptId);
    }

    /**
     * 电子名片-部门管理-获取同级部门列表
     * @param legalManDeptId
     * @return
     */
    @Override
    public EcardApiSysDept getDepInfo(Long deptId, String salt) {
        EcardApiSysDept depInfo = ecardApiSysDeptMapper.getDepInfo(deptId);
        if (depInfo != null) {
            try {
                //数据解密（手机号、身份证号）
                if (!StringUtils.objIsNullOrEmpty(depInfo.getPhone())) {
                    depInfo.setPhone(AESEncryptionUtils.decrypt(depInfo.getPhone(), salt));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return depInfo;
    }

    /**
     * 根据参数配置展示法人下指定类型的机构
     * @param legalManDeptId
     * @param ecardMerchantIsdept 0：查询各分支机构（支行、分理处）业务数据，1：查询各分支机构及部室数据
     * @return
     */
    @Override
    public List<EcardApiSysDept> getDeptsByConfig(Long legalManDeptId, String ecardMerchantIsdept) {
        return ecardApiSysDeptMapper.getDeptsByConfig(legalManDeptId, ecardMerchantIsdept);
    }
}
